package co.droidforum.foodx.utils;

import java.security.Key;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import android.util.Log;

public class DroidEncryption {

	public static byte[] encrypt( byte[] source ) {
		try {
			Key key = getKey();
			Cipher desCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
			desCipher.init(Cipher.ENCRYPT_MODE, key);
			return desCipher.doFinal(source);
		} catch( Exception e ) {
			
		}
		return null;
	}
	
	public static byte[] decrypt( byte[] source ) {
		try {
			Key key = getKey();
			Cipher desCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
			desCipher.init(Cipher.DECRYPT_MODE, key);
			return desCipher.doFinal(source);
		} catch( Exception e ) {
			Log.d("ERRRRRRRRROOOOOOORRRRRRR", e.getMessage());
		}
		return null;
	}
	
	private static Key getKey() {
		try {
			byte[] keyBytes = new byte[]{9, 23, 88, 123, 4, -43, 57, -87, 45, 23, 123, -123, 00, 43, -57, 87};
			return new SecretKeySpec(keyBytes, "AES");
		}catch( Exception e ) {
		}
		return null;
	}
	
}
